﻿using System;

namespace Evaluant.NLinq.Expressions
{
    public class LambdaExpression : Expression
    {
        public LambdaExpression(Expression argument, Expression body)
            : this(new BlockExpression(), body)
        {
            Arguments.Add(argument);
        }

        public LambdaExpression(BlockExpression arguments, Expression body)
        {
            Arguments = arguments;
            Body = body;
        }

        public BlockExpression Arguments { get; set; }

        public Expression Body { get; set; }

        public override void Accept(NLinqVisitor visitor)
        {
            visitor.Visit(this);
        }

        public override ExpressionTypes ExpressionType
        {
            get { return ExpressionTypes.Lambda; }
        }

        public override string ToString()
        {
            if (Arguments.Count == 1)
                return Arguments[0] + "=>" + Body;
            else
                return "(" + Arguments + ")" + "=>" + Body;
        }
    }
}
